<!--
	时间：2019-07-25
	描述：融资合同报表
-->

<template>
	<div class="m-view-fincontractReport m-window">
		<!--查询条件（对账月份）-->
		<div class="m-condition">
			<el-row :gutter="10">
				<el-form
				 :model="ruleForm"
				 ref="ruleForm"
				 label-width="70px"
				 :inline-message="true"
				 label-position="left"
				>
                    <el-col :span="3">
                        <el-input placeholder="申请编号" clearable 
                        @keyup.enter.native="searchReport(7)" @clear="focusInput('s_itemNo')" ref="s_itemNo"
                        v-model="itemNo"></el-input>
                    </el-col>
                    <el-col :span="8">
                        <el-date-picker 
                            @change="focusInput('s_itemNo')"
                            v-model="signDateArr" type="daterange" range-separator="至"
                            start-placeholder="签署-开始日期" end-placeholder="签署-结束日期" value-format="yyyy-MM-dd"></el-date-picker>
                    </el-col>
					<el-col :span="3">
						<!-- <el-form-item label="签署状态" class="rightItem"> -->
							<el-select
							 value-key=""
							 v-model="signCode"
							 placeholder="签署状态"
							 @change="focusInput('s_letterMonth')" ref="s_letterMonth"
							 clearable
							>
								<el-option
								 v-for="item in signOptions"
								 :key="item.value"
								 :label="item.label"
								 :value="item.value"
								>
								</el-option>
							</el-select>
						<!-- </el-form-item> -->
					</el-col>
					<el-col :span="2">
						<el-button type="primary" @click="searchReport(7)">查询</el-button>
					</el-col>
				</el-form>
			</el-row>
		</div>
		<!--融资合同列表-->
		<div class="m-agTable m-bottom m-top2">
			 <ag-grid-vue  
			class="m-agTableContent ag-theme-balham" 
			:gridOptions="reportGridOptions" 
			:columnDefs="reportColumnDefs" 
			:rowData="rowData"  
			v-loading="loading" 
			rowSelection="single"
			></ag-grid-vue>
		</div>
		<!--分页-->
		<div class="m-page" v-if="diaShow">
			<el-pagination
				@size-change="reportHandleSizeChange"
				@current-change="reportHandleCurrentChange"
				@prev-click="reportHandlePrevClick"
				@next-click="reportHandleNextClick"
				:current-page="reportCurrentPage"
				:page-sizes="[30,50,100,150,200]"
				:page-size="reportPageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="reportTotal"
			></el-pagination>
		</div>
	</div>
</template>

<style lang="less">
    .m-view-fincontractReport{
       .el-form-item {
            margin-bottom: 0px;
        } 
    }
</style>

<script>
    import {formatPrice} from '@/util/format'
	import supplierInfo from "@/public/supplierInfo.js";
	import localeText from "@/i18n/agGridText";
    import _APIS from "@/api";
    import gridOptions from 'lesso-common/public/gridOptions';
    export default{
        props: {

        },
        data(){
            return{
                ruleForm:{},
                itemNo:'',
                signDateArr:[],
                supplierId:this.$store.state.supplyChainFinance.custInf.custId, //获取供应商id
                signCode:'',
                //签署状态
                signOptions:[
                {	value:0,label:"未进行"},
                {	value:1,label:"进行中"},
                {	value:2,label:"已完成"},
                {	value:3,label:"已作废"}],
				//ag-grid配置
				reportGridOptions:'',
				reportColumnDefs: [],
				RowSelection: "multiple",
				rowData:[],
				loading:false,
				reportCurrentPage:1,//当前页码
				reportPageSize:30,//页容量
				reportTotal:0,//数据总量

				//缓存搜索条件
				tempSearch:{
                    itemNo:"",
                    signDateArr:[],
					signCode:"",
					supplierId:"",
				},
				permission:'',
				diaShow:true,
				supplierInfo: [],
				//comOptions: [], //公司列表
            }
            
        },
        created() {
			//this.getAuthInfo()
			//this.bindmonth()
			//this.searchReport(7)
        },
        beforeMount(){
			// 页面 ag-grid 配置
			this.reportGridOptions = Object.assign({
				context: {
					componentParent: this
				},
				enableColResize: true,
				localeText: localeText,
				enableCellChangeFlash: true,
				suppressRowClickSelection: true,
				enableFilter: true, //列过滤器
				enableSorting: true, //列排序
			},gridOptions())

			//配置列表字段
			this.reportColumnDefs = [
                {headerName: "申请编号", field: "itemNo", width:120},
                {headerName: "合同名称", field: "name", width:120},
				{headerName: "合同编号", field: "contractNo", width:120},
				{headerName: "签署时间", field: "updateTime",valueFormatter: params => {return this.formatDate(params.value)}, width:120},
				// {headerName: "合同生效时间（融资开始日）", field: "", width:120},
				{headerName: "签署状态", field: "signStatus", width:120},
				{headerName: "合同备注", field: "remark", width:120},
				{headerName: "创建时间", field: "createTime",valueFormatter: params => {return this.formatDate(params.value)}, width:120},
			]
        },
        mounted() {
			//this.searchReport(7)
        },
        methods:{
            reportHandleSizeChange (params) {
				this.reportPageSize = params;
				this.getTempSearch();
				this.searchReport();
            },
            reportHandleCurrentChange (params) {
				this.reportCurrentPage = params;
				this.getTempSearch();
				this.searchReport();
            },
            reportHandlePrevClick () {
				this.reportCurrentPage = this.reportCurrentPage - 1;
				this.getTempSearch();
            },
            reportHandleNextClick () {
				this.reportCurrentPage += 1;
				this.getTempSearch();
            },
            //查询报表
			searchReport(type){
				var that = this;
				if(type === 7){
					this.reportCurrentPage = 1;
				}
				
				this.loading = true;
				that.saveTempSearch(); //缓存搜索条件

                console.log('111',that.$global.user.userTypeId)
				_APIS.queryAttachmentInfo({
					entity:{
                        userTypeId:that.$global.user.userTypeId,
                        custId:that.supplierId,
                        itemNo:that.itemNo,
                        signDateStart:that.signDateArr?that.signDateArr[0]:'',
                        signDateEnd:that.signDateArr?that.signDateArr[1]:'',
                        signStatus:that.signCode,
                    },
					current: that.reportCurrentPage,
                	size: that.reportPageSize,
				}).then(function success (response){
                    var data = response.data;
					if(data.code == 200){
                        //that.rowData = data.rows;
                        that.rowData = data.rows
                        // .filter((item)=>{
                        //     return item.type == 1 || item.type == 0
                        // })
						that.rowData.forEach(item=>{
                            if(item.signStatus === 0){
                                item.signStatus = '未签署';
                            }else if(item.signStatus === 1){
                                item.signStatus = '签署中';
                            }else if(item.signStatus === 2){
								item.signStatus = '签署完成';
							}else{
                                item.signStatus = '已作废';
                            }

                            //console.log(that.isContains(item.name, '中登资料'))
                            // if(that.isContains(item.name, '中登资料')){
                            //     that.rowData.splice(item,1)
                            // }
						})
						
						that.reportTotal = data.total;
                        that.loading = false;
					}else{
						that.$alert(data.info, {
							showClose: false,
							confirmButton: "确定",
							customClass: "alertFailure"
							}).then(() => {
							that.reportTotal = 0;
							that.loading = false;
						});
					}
				},function error(err){
					that.$alert("网络异常，查询失败！", {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
						}).then(() => {
						that.reportTotal = 0;
						that.loading = false;
					});
				})
            },
            //缓存查询条件
			saveTempSearch(){
                this.tempSearch.supplierId = this.supplierId;
				this.tempSearch.itemNo = this.itemNo;
				this.tempSearch.signDateArr = this.signDateArr;
				this.tempSearch.signCode = this.signCode;
            },
            //读取缓存查询数据
			getTempSearch(){
				this.supplierId = this.tempSearch.supplierId;
				this.itemNo = this.tempSearch.itemNo;
                this.signDateArr = this.tempSearch.signDateArr;
                this.signCode = this.tempSearch.signCode;
            },
            //时间截止到天
			formatDate(time) {
				if (time) {
					return time.substring(0, 10)
				} else {
					return ''
				}
            },
            focusInput(refName){
				if(refName === 's_letterMonth'){
				this.searchReport(7)
				return
				}
				this.$refs[refName].focus()
            },
            isContains(str, substr){
                return str.indexOf(substr) >= 0;
            }
        },
        components: {

        },
        watch: {

		},
    }
</script>